package com.wsllx.util;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;

/**
 * @Description: 根据模板获取流
 * @Author: llx
 * @Date: 2023.08.0912:32
 * @Copyright: Fujian Linewell Software Co., Ltd. All rights reserved.
 */
@Component
public class ExelUtil {
    public  void getStream(String path,OutputStream outputStream) throws IOException {
        //String path = ResourceUtils.getURL("classpath:bmoTemplate.xlsx").getPath();
        InputStream inputStream = this.getClass().getResourceAsStream(path);
        getStream(inputStream, outputStream);
    }

    public  void getStream(InputStream inputStream, OutputStream outputStream) throws IOException {
        try {
            Workbook workbook = new XSSFWorkbook(inputStream);

            // 写入
            workbook.write(outputStream);
        } catch (Exception ex) {
            System.out.println("坏了");
        }

    }
}
